package top.tanglizhi.springboot3.controller;

import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.tanglizhi.springboot3.base.R;
import top.tanglizhi.springboot3.entity.TbFiles;
import top.tanglizhi.springboot3.service.FileService;

@RestController
@RequestMapping("/files")
@RequiredArgsConstructor
public class FileController {

    private final FileService fileService;

    @PostMapping
    public R<TbFiles> upload(MultipartFile file) {
        return fileService.upload(file);
    }

    @GetMapping("/{id}")
    public void download(@PathVariable Integer id, HttpServletResponse response) {
        fileService.download(id, response);
    }

}
